package menu

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/admin"

	"github.com/gin-gonic/gin"
)

func List(c *gin.Context) {
	requestDataMap := make(map[string]interface{})
	c.ShouldBindJSON(&requestDataMap)

	where, _, _ := controller.WhereStructure(requestDataMap)

	//查询信息
	var adminAuthRuleStruct admin.AdminAuthRuleStruct
	var adminAuthRuleData []admin.AdminAuthRuleStruct
	model.GetModelData(
		model.Db,
		adminAuthRuleStruct.TableName(),
		&adminAuthRuleData,
		model.QueryOptions{
			Conditions: where,
			OrderBy:    "id asc",
			Debug:      true,
		},
	)

	//数据格式化
	returnData := make([]map[string]interface{}, 0)
	for _, v := range adminAuthRuleData {
		returnData = append(returnData, map[string]interface{}{
			"id":         v.Id,
			"parentId":   v.ParentId,
			"menuType":   0,
			"title":      v.Title,
			"name":       v.Name,
			"path":       v.Path,
			"component":  v.Component,
			"rank":       v.Rank,
			"showParent": controller.IntToBool(v.ShowParent),
			"icon":       v.Icon,
			"showLink":   controller.IntToBool(v.ShowLink),
		})
	}

	controller.Success(c, returnData)
}
